package com.neusoft.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.mapper.BusinessMapper;
import com.neusoft.po.Business;
import com.neusoft.service.BusinessService;

@Service
public class BusinessServiceImpl implements BusinessService {

	@Autowired
	private BusinessMapper businessMapper;

	@Override
	public List<Business> listBusinessByOrderTypeId(Integer orderTypeId) {
		return businessMapper.listBusinessByOrderTypeId(orderTypeId);
	}

	@Override
	public Business getBusinessById(Integer businessId) {
		return businessMapper.getBusinessById(businessId);
	}

	@Override
	public List<Business> listBusinessBySearch(String prompt) {
		String[] keywords = prompt.split(" |,|、");
		List<Business> result = new ArrayList<>();
		Set<Integer> existedBusinessId = new HashSet<>(); // 假设 Business 有唯一 id
		for (String keyword : keywords) {
			List<Business> businesses = businessMapper.listBusinessBySearch(keyword);
			for (Business business : businesses) {
				// 根据唯一标识（如 id）判断是否已存在
				if (!existedBusinessId.contains(business.getBusinessId())) {
					result.add(business);
					existedBusinessId.add(business.getBusinessId());
				}
			}
		}
		return result;
	}
}
